﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Threading;
using BackupRestoreSoftwares;

namespace BackupRestoreSoftwares.FormChild
{
    public partial class m_Main : UserControl
    {
        public m_Main()
        {
            InitializeComponent();
        }

        string Roaming_path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).ToString();
		string Local_path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData).ToString();
		string Common_path = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData).ToString();
		string Program_32 = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles).ToString();
		string Program_64 = Path.GetPathRoot(Environment.SystemDirectory).ToString() + "Program Files";
        string App_path = Application.StartupPath.ToString();
		bool Is64 = Environment.Is64BitOperatingSystem;

        #region Rar - Compress - Extract
        private void CompressRAR(string rar_file, string path_file)
        {
            // - \" Thêm vào một dấu nháy kép ("")
            ProcessStartInfo ps = new ProcessStartInfo();
            ps.FileName = @"Rar.exe";
            ps.Arguments = "a -r -ep1 \"" + rar_file + "\" \"" + path_file + "\"";
            //ps.Arguments = "a -r -ep1 \"" + rar_file + "\" \"" + source + "\" -mx=9";
            //               1              2                       3               4
            ps.WindowStyle = ProcessWindowStyle.Hidden;
            Process proc = Process.Start(ps);
            proc.WaitForExit();
        }

        private void ExtractRAR(string rar_file, string path_file)
        {
            ProcessStartInfo ps = new ProcessStartInfo();
            ps.FileName = @"Rar.exe";
            ps.Arguments = "x -y \"" + rar_file + "\" \"" + path_file + "\"";
            ps.WindowStyle = ProcessWindowStyle.Hidden;
            Process proc = Process.Start(ps);
            proc.WaitForExit();
        }
        #endregion

        #region ClearCache
        private void ClearChrome()
        {
            string chkfile = Program_32 + @"\Google\Chrome\Application\chrome.exe";
            if (File.Exists(chkfile))
            {
                foreach (Process app in Process.GetProcesses())
                    if (app.ProcessName == "chrome")
                        app.Kill();
            }

            string chrome_path = Local_path + @"\Google\Chrome\User Data\Profile 1\Cache";
            if (Directory.Exists(chrome_path) == true)
            {
                try
                {
                    DirectoryInfo di = new DirectoryInfo(chrome_path);
                    FileInfo fi = new FileInfo(chrome_path);
                    foreach (string fileName1 in Directory.GetFiles(chrome_path, "*", SearchOption.AllDirectories))
                    {
                        FileInfo fileInfo1 = new FileInfo(fileName1);
                        fileInfo1.Delete();
                    }
                    foreach (string fileName in Directory.GetDirectories(chrome_path, "*", SearchOption.AllDirectories))
                    {
                        DirectoryInfo fileInfo = new DirectoryInfo(fileName);
                        fileInfo.Delete();
                    }
                }
                catch
                {
                }
            }
            string chrome_path_media = Local_path + @"\Google\Chrome\User Data\Profile 1\Media Cache";
            if (Directory.Exists(chrome_path_media) == true)
            {
                try
                {
                    DirectoryInfo di = new DirectoryInfo(chrome_path_media);
                    FileInfo fi = new FileInfo(chrome_path_media);
                    foreach (string fileName1 in Directory.GetFiles(chrome_path_media, "*", SearchOption.AllDirectories))
                    {
                        FileInfo fileInfo1 = new FileInfo(fileName1);
                        fileInfo1.Delete();
                    }
                    foreach (string fileName in Directory.GetDirectories(chrome_path_media, "*", SearchOption.AllDirectories))
                    {
                        DirectoryInfo fileInfo = new DirectoryInfo(fileName);
                        fileInfo.Delete();
                    }
                }
                catch
                {
                }
            }
            string chrome_path_wide = Local_path + @"\Google\Chrome\User Data\WidevineCDM";
            if (Directory.Exists(chrome_path_wide) == true)
            {
                try
                {
                    DirectoryInfo di = new DirectoryInfo(chrome_path_wide);
                    FileInfo fi = new FileInfo(chrome_path_wide);
                    foreach (string fileName1 in Directory.GetFiles(chrome_path_wide, "*", SearchOption.AllDirectories))
                    {
                        FileInfo fileInfo1 = new FileInfo(fileName1);
                        fileInfo1.Delete();
                    }
                    foreach (string fileName in Directory.GetDirectories(chrome_path_wide, "*", SearchOption.AllDirectories))
                    {
                        DirectoryInfo fileInfo = new DirectoryInfo(fileName);
                        fileInfo.Delete();
                    }
                }
                catch
                {
                }
            }
            string chrome_path_swift = Local_path + @"\Google\Chrome\User Data\SwiftShader";
            if (Directory.Exists(chrome_path_swift) == true)
            {
                try
                {
                    DirectoryInfo di = new DirectoryInfo(chrome_path_swift);
                    FileInfo fi = new FileInfo(chrome_path_swift);
                    foreach (string fileName1 in Directory.GetFiles(chrome_path_swift, "*", SearchOption.AllDirectories))
                    {
                        FileInfo fileInfo1 = new FileInfo(fileName1);
                        fileInfo1.Delete();
                    }
                    foreach (string fileName in Directory.GetDirectories(chrome_path_swift, "*", SearchOption.AllDirectories))
                    {
                        DirectoryInfo fileInfo = new DirectoryInfo(fileName);
                        fileInfo.Delete();
                    }
                }
                catch
                {
                }
            }
            string chrome_path_pna = Local_path + @"\Google\Chrome\User Data\pnacl";
            if (Directory.Exists(chrome_path_pna) == true)
            {
                try
                {
                    DirectoryInfo di = new DirectoryInfo(chrome_path_pna);
                    FileInfo fi = new FileInfo(chrome_path_pna);
                    foreach (string fileName1 in Directory.GetFiles(chrome_path_pna, "*", SearchOption.AllDirectories))
                    {
                        FileInfo fileInfo1 = new FileInfo(fileName1);
                        fileInfo1.Delete();
                    }
                    foreach (string fileName in Directory.GetDirectories(chrome_path_pna, "*", SearchOption.AllDirectories))
                    {
                        DirectoryInfo fileInfo = new DirectoryInfo(fileName);
                        fileInfo.Delete(true);
                    }
                }
                catch
                {
                }
            }

        }
        private void ClearCoRom()
        {
            string chkfile = Local_path + @"\CocCoc\Browser\Application\browser.exe";
            if (File.Exists(chkfile))
            {
                foreach (Process app in Process.GetProcesses())
                    if (app.ProcessName == "browser")
                        app.Kill();
            }

            string corom_path = Local_path + @"\CocCoc\Browser\User Data\Default\Cache";
            if (Directory.Exists(corom_path) == true)
            {
                try
                {
                    DirectoryInfo di = new DirectoryInfo(corom_path);
                    FileInfo fi = new FileInfo(corom_path);
                    foreach (string fileName1 in Directory.GetFiles(corom_path, "*", SearchOption.AllDirectories))
                    {
                        FileInfo fileInfo1 = new FileInfo(fileName1);
                        fileInfo1.Delete();
                    }
                    foreach (string fileName in Directory.GetDirectories(corom_path, "*", SearchOption.AllDirectories))
                    {
                        DirectoryInfo fileInfo = new DirectoryInfo(fileName);
                        fileInfo.Delete();
                    }
                }
                catch
                {
                }
            }

        }
        private void ClearSnippets()
        {
            string chkfile = Program_32 + @"\Snippets\Snippets.exe";
            if (File.Exists(chkfile))
            {
                foreach (Process app in Process.GetProcesses())
                    if (app.ProcessName == "Snippets")
                        app.Kill();
            }

            string snippets_path = Local_path + @"\Snippets\Backups";
            if (Directory.Exists(snippets_path) == true)
            {
                try
                {
                    DirectoryInfo di = new DirectoryInfo(snippets_path);
                    FileInfo fi = new FileInfo(snippets_path);
                    foreach (string fileName1 in Directory.GetFiles(snippets_path, "*", SearchOption.AllDirectories))
                    {
                        FileInfo fileInfo1 = new FileInfo(fileName1);
                        fileInfo1.Delete();
                    }
                    foreach (string fileName in Directory.GetDirectories(snippets_path, "*", SearchOption.AllDirectories))
                    {
                        DirectoryInfo fileInfo = new DirectoryInfo(fileName);
                        fileInfo.Delete();
                    }
                }
                catch
                {
                }
            }
        }
        private void ClearEvernote()
        {
            string chkfile = Program_32 + @"\Evernote\Evernote\Evernote.exe";
            if (File.Exists(chkfile))
            {
                foreach (Process app in Process.GetProcesses())
                    if (app.ProcessName == "Evernote")
                        app.Kill();
            }

            string evernote_path = Local_path + @"\Evernote\Evernote\AutoUpdate";
            if (Directory.Exists(evernote_path) == true)
            {
                try
                {
                    DirectoryInfo di = new DirectoryInfo(evernote_path);
                    FileInfo fi = new FileInfo(evernote_path);
                    foreach (string fileName1 in Directory.GetFiles(evernote_path, "*", SearchOption.AllDirectories))
                    {
                        FileInfo fileInfo1 = new FileInfo(fileName1);
                        fileInfo1.Delete();
                    }
                    foreach (string fileName in Directory.GetDirectories(evernote_path, "*", SearchOption.AllDirectories))
                    {
                        DirectoryInfo fileInfo = new DirectoryInfo(fileName);
                        fileInfo.Delete();
                    }
                }
                catch
                {
                }
            }
        }
        #endregion

        #region Button
        private void frmDevelop_Load(object sender, EventArgs e)
        {
            if (File.Exists(App_path + @"\DBBACKUP") != true)
            {
                Directory.CreateDirectory(App_path + @"\DBBACKUP");
            }
        }

        private void btn_bk_notepad_Click(object sender, EventArgs e)
        {
            if (File.Exists(App_path + @"\DBBACKUP\Notepad++") != true)
            {
                Directory.CreateDirectory(App_path + @"\DBBACKUP\Notepad++");
            }
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                string chkfile = Program_32 + @"\Notepad++\notepad++.exe";
                if (File.Exists(chkfile))
                {
                    foreach (Process app in Process.GetProcesses())
                        if (app.ProcessName == "notepad++")
                            app.Kill();
                    string rar_file = App_path + @"\DBBACKUP\Notepad++\Notepad++.rar";
                    string path_file = Roaming_path + @"\Notepad++\";
                    CompressRAR(rar_file, path_file);
                    string rar_file_plug = App_path + @"\DBBACKUP\Notepad++\plugins.rar";
                    string path_file_plug = Program_32 + @"\Notepad++\plugins\";
                    CompressRAR(rar_file_plug, path_file_plug);

                    t.Abort();
                    MessageBox.Show("Backup completed!", "Finish");
                }
                else
                {
                    t.Abort();
                    MessageBox.Show("Notepad++ don't install!", "Error");
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }
        }

        private void btn_res_notepad_Click(object sender, EventArgs e)
        {
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                string chkfile = Program_32 + @"\Notepad++\notepad++.exe";
                if (File.Exists(chkfile))
                {
                    foreach (Process app in Process.GetProcesses())
                        if (app.ProcessName == "notepad++")
                            app.Kill();
                    string rar_file = App_path + @"\DBBACKUP\Notepad++\Notepad++.rar";
                    string path_file = Roaming_path + @"\Notepad++\";
                    ExtractRAR(rar_file, path_file);
                    string rar_file_plug = App_path + @"\DBBACKUP\Notepad++\plugins.rar";
                    string path_file_plug = Program_32 + @"\Notepad++\plugins\";
                    ExtractRAR(rar_file_plug, path_file_plug);

                    t.Abort();
                    MessageBox.Show("Restore completed!", "Finish");
                }
                else
                {
                    t.Abort();
                    MessageBox.Show("Notepad++ don't install!", "Error");
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }
        }

        private void btn_bk_sublime_Click(object sender, EventArgs e)
        {
            if (File.Exists(App_path + @"\DBBACKUP\SublimeText2") != true)
            {
                Directory.CreateDirectory(App_path + @"\DBBACKUP\SublimeText2");
            }
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                if (Is64 == true)
                {
                    string chkfile_64 = Program_64 + @"\Sublime Text 2\sublime_text.exe";
                    string chkfile_32 = Program_32 + @"\Sublime Text 2\sublime_text.exe";
                    if (File.Exists(chkfile_64) || File.Exists(chkfile_32))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "sublime_text")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\SublimeText2\Sublime2.rar";
                        string path_file = Roaming_path + @"\Sublime Text 2\";
                        CompressRAR(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Backup completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Sublime Text 2 don't install!", "Error"); 
                    }
                }
                else
                {
                    string chkfile_32 = Program_32 + @"\Sublime Text 2\sublime_text.exe";
                    if (File.Exists(chkfile_32))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "sublime_text")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\SublimeText2\Sublime2.rar";
                        string path_file = Roaming_path + @"\Sublime Text 2\";
                        CompressRAR(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Backup completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Sublime Text 2 don't install!", "Error");
                    }
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }
            
        }

        private void btn_res_sublime_Click(object sender, EventArgs e)
        {
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                if (Is64 == true)
                {
                    string chkfile_64 = Program_64 + @"\Sublime Text 2\sublime_text.exe";
                    string chkfile_32 = Program_32 + @"\Sublime Text 2\sublime_text.exe";
                    if (File.Exists(chkfile_64) || File.Exists(chkfile_32))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "sublime_text")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\SublimeText2\Sublime2.rar";
                        string path_file = Roaming_path + @"\Sublime Text 2\";
                        ExtractRAR(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Restore completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Sublime Text 2 don't install!", "Error");
                    }
                }
                else
                {
                    string chkfile_32 = Program_32 + @"\Sublime Text 2\sublime_text.exe";
                    if (File.Exists(chkfile_32))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "sublime_text")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\SublimeText2\Sublime2.rar";
                        string path_file = Roaming_path + @"\Sublime Text 2\";
                        ExtractRAR(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Restore completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Sublime Text 2 don't install!", "Error");
                    }
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }
        }

        private void btn_bk_subtext3_Click(object sender, EventArgs e)
        {
            if (File.Exists(App_path + @"\DBBACKUP\SublimeText3") != true)
            {
                Directory.CreateDirectory(App_path + @"\DBBACKUP\SublimeText3");
            }
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                if (Is64 == true)
                {
                    string chkfile_64 = Program_64 + @"\Sublime Text 3\sublime_text.exe";
                    string chkfile_32 = Program_32 + @"\Sublime Text 3\sublime_text.exe";
                    if (File.Exists(chkfile_64) || File.Exists(chkfile_32))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "sublime_text")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\SublimeText3\Sublime3.rar";
                        string path_file = Roaming_path + @"\Sublime Text 3\";
                        CompressRAR(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Backup completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Sublime Text 3 don't install!", "Error");
                    }
                }
                else
                {
                    string chkfile_32 = Program_32 + @"\Sublime Text 3\sublime_text.exe";
                    if (File.Exists(chkfile_32))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "sublime_text")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\SublimeText3\Sublime3.rar";
                        string path_file = Roaming_path + @"\Sublime Text 3\";
                        CompressRAR(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Backup completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Sublime Text 3 don't install!", "Error");
                    }
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }
        }

        private void btn_res_subtext3_Click(object sender, EventArgs e)
        {
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                if (Is64 == true)
                {
                    string chkfile_64 = Program_64 + @"\Sublime Text 3\sublime_text.exe";
                    string chkfile_32 = Program_32 + @"\Sublime Text 3\sublime_text.exe";
                    if (File.Exists(chkfile_64) || File.Exists(chkfile_32))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "sublime_text")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\SublimeText3\Sublime3.rar";
                        string path_file = Roaming_path + @"\Sublime Text 3\";
                        ExtractRAR(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Restore completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Sublime Text 3 don't install!", "Error");
                    }
                }
                else
                {
                    string chkfile_32 = Program_32 + @"\Sublime Text 3\sublime_text.exe";
                    if (File.Exists(chkfile_32))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "sublime_text")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\SublimeText3\Sublime3.rar";
                        string path_file = Roaming_path + @"\Sublime Text 3\";
                        ExtractRAR(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Restore completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Sublime Text 3 don't install!", "Error");
                    }
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }
        }

        private void btn_bk_chrome_Click(object sender, EventArgs e)
        {
            ClearChrome();
            if (File.Exists(App_path + @"\DBBACKUP\Chrome") != true)
            {
                Directory.CreateDirectory(App_path + @"\DBBACKUP\Chrome");
            }
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                string chkfile = Program_32 + @"\Google\Chrome\Application\chrome.exe";
                if (File.Exists(chkfile))
                {
                    foreach (Process app in Process.GetProcesses())
                        if (app.ProcessName == "chrome")
                            app.Kill();
                    string rar_file = App_path + @"\DBBACKUP\Chrome\User_Data.rar";
                    string path_file = Local_path + @"\Google\Chrome\User Data\";
                    CompressRAR(rar_file, path_file);

                    t.Abort();
                    MessageBox.Show("Backup completed!", "Finish");
                }
                else
                {
                    t.Abort();
                    MessageBox.Show("Chrome don't install!", "Error");
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }
        }

        private void btn_res_chrome_Click(object sender, EventArgs e)
        {
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                string chkfile = Program_32 + @"\Google\Chrome\Application\chrome.exe";
                if (File.Exists(chkfile))
                {
                    foreach (Process app in Process.GetProcesses())
                        if (app.ProcessName == "chrome")
                            app.Kill();
                    string rar_file = App_path + @"\DBBACKUP\Chrome\User_Data.rar";
                    string path_file = Local_path + @"\Google\Chrome\User Data\";
                    ExtractRAR(rar_file, path_file);

                    t.Abort();
                    MessageBox.Show("Restore completed!", "Finish");
                }
                else
                {
                    t.Abort();
                    MessageBox.Show("Chrome don't install!", "Error");
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }
        }

        private void btn_bk_opera_Click(object sender, EventArgs e)
        {
            if (File.Exists(App_path + @"\DBBACKUP\Opera") != true)
            {
                Directory.CreateDirectory(App_path + @"\DBBACKUP\Opera");
            }
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                if (Is64 == true)
                {
                    string chkfile_64 = Program_64 + @"\Opera\launcher.exe";
                    string chkfile_32 = Program_32 + @"\Opera\launcher.exe";
                    if (File.Exists(chkfile_64) || File.Exists(chkfile_32))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "opera")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\Opera\Opera_Data.rar";
                        string path_file = Roaming_path + @"\Opera Software\Opera Stable\";
                        CompressRAR(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Backup completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Opera Browser don't install!", "Error");
                    }
                }
                else
                {
                    string chkfile_32 = Program_32 + @"\Opera\launcher.exe";
                    if (File.Exists(chkfile_32))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "opera")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\Opera\Opera_Data.rar";
                        string path_file = Roaming_path + @"\Opera Software\Opera Stable\";
                        CompressRAR(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Backup completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Opera Browser don't install!", "Error");
                    }
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }

        }

        private void btn_res_opera_Click(object sender, EventArgs e)
        {
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                if (Is64 == true)
                {
                    string chkfile_64 = Program_64 + @"\Opera\launcher.exe";
                    string chkfile_32 = Program_32 + @"\Opera\launcher.exe";
                    if (File.Exists(chkfile_64) || File.Exists(chkfile_32))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "opera")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\Opera\Opera_Data.rar";
                        string path_file = Roaming_path + @"\Opera Software\Opera Stable\";
                        ExtractRAR(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Restore completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Opera Browser don't install!", "Error");
                    }
                }
                else
                {
                    string chkfile_32 = Program_32 + @"\Opera\launcher.exe";
                    if (File.Exists(chkfile_32))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "opera")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\Opera\Opera_Data.rar";
                        string path_file = Roaming_path + @"\Opera Software\Opera Stable\";
                        ExtractRAR(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Restore completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Opera Browser don't install!", "Error");
                    }
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }
        }

        private void btn_bk_firrefox_Click(object sender, EventArgs e)
        {
            if (File.Exists(App_path + @"\DBBACKUP\Firefox") != true)
            {
                Directory.CreateDirectory(App_path + @"\DBBACKUP\Firefox");
            }
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                string chkfile = Program_32 + @"\Mozilla Firefox\firefox.exe";
                if (File.Exists(chkfile))
                {
                    foreach (Process app in Process.GetProcesses())
                        if (app.ProcessName == "firefox")
                            app.Kill();
                    string rar_file = App_path + @"\DBBACKUP\Firefox\Firefox_Data.rar";
                    string path_file = Roaming_path + @"\Mozilla\Firefox\";
                    CompressRAR(rar_file, path_file);

                    t.Abort();
                    MessageBox.Show("Backup completed!", "Finish");
                }
                else
                {
                    t.Abort();
                    MessageBox.Show("Mozilla Firefox don't install!", "Error");
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }
        }

        private void btn_res_firefox_Click(object sender, EventArgs e)
        {
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                string chkfile = Program_32 + @"\Mozilla Firefox\firefox.exe";
                if (File.Exists(chkfile))
                {
                    foreach (Process app in Process.GetProcesses())
                        if (app.ProcessName == "firefox")
                            app.Kill();
                    string rar_file = App_path + @"\DBBACKUP\Firefox\Firefox_Data.rar";
                    string path_file = Roaming_path + @"\Mozilla\Firefox\";
                    ExtractRAR(rar_file, path_file);

                    t.Abort();
                    MessageBox.Show("Restore completed!", "Finish");
                }
                else
                {
                    t.Abort();
                    MessageBox.Show("Mozilla Firefox don't install!", "Error");
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }
        }

        private void btn_bk_corom_Click(object sender, EventArgs e)
        {
            ClearCoRom();
            if (File.Exists(App_path + @"\DBBACKUP\CoRom") != true)
            {
                Directory.CreateDirectory(App_path + @"\DBBACKUP\CoRom");
            }
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                string chkfile = Local_path + @"\CocCoc\Browser\Application\browser.exe";
                if (File.Exists(chkfile))
                {
                    foreach (Process app in Process.GetProcesses())
                        if (app.ProcessName == "browser")
                            app.Kill();
                    string rar_file = App_path + @"\DBBACKUP\CoRom\CoRom_Data.rar";
                    string path_file = Local_path + @"\CocCoc\Browser\User Data\";
                    CompressRAR(rar_file, path_file);

                    t.Abort();
                    MessageBox.Show("Backup completed!", "Finish");
                }
                else
                {
                    t.Abort();
                    MessageBox.Show("CoRom+ don't install!", "Error");
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }
        }

        private void btn_res_corom_Click(object sender, EventArgs e)
        {
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                string chkfile = Local_path + @"\CocCoc\Browser\Application\browser.exe";
                if (File.Exists(chkfile))
                {
                    foreach (Process app in Process.GetProcesses())
                        if (app.ProcessName == "browser")
                            app.Kill();
                    string rar_file = App_path + @"\DBBACKUP\CoRom\CoRom_Data.rar";
                    string path_file = Local_path + @"\CocCoc\Browser\User Data\";
                    ExtractRAR(rar_file, path_file);

                    t.Abort();
                    MessageBox.Show("Restore completed!", "Finish");
                }
                else
                {
                    t.Abort();
                    MessageBox.Show("CoRom+ don't install!", "Error");
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }
        }

        private void btn_bk_phpDesign_Click(object sender, EventArgs e)
        {
            if (File.Exists(App_path + @"\DBBACKUP\phpDesigner") != true)
            {
                Directory.CreateDirectory(App_path + @"\DBBACKUP\phpDesigner");
            }
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                string chkfile = Program_32 + @"\phpDesigner 8\phpDesigner.exe";
                if (File.Exists(chkfile))
                {
                    foreach (Process app in Process.GetProcesses())
                        if (app.ProcessName == "phpDesigner")
                            app.Kill();
                    string rar_file = App_path + @"\DBBACKUP\phpDesigner\phpDesigner_Data.rar";
                    string path_file = Roaming_path + @"\phpDesigner\";
                    CompressRAR(rar_file, path_file);
                    File.Copy(Roaming_path + @"\phpdesigner.xml", App_path + @"\DBBACKUP\phpDesigner\phpdesigner.xml", true);

                    t.Abort();
                    MessageBox.Show("Backup completed!", "Finish");
                }
                else
                {
                    t.Abort();
                    MessageBox.Show("phpDesigner 8 don't install!", "Error");
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }
        }

        private void btn_res_phpdesign_Click(object sender, EventArgs e)
        {
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                string chkfile = Program_32 + @"\phpDesigner 8\phpDesigner.exe";
                if (File.Exists(chkfile))
                {
                    foreach (Process app in Process.GetProcesses())
                        if (app.ProcessName == "phpDesigner")
                            app.Kill();
                    string rar_file = App_path + @"\DBBACKUP\phpDesigner\phpDesigner_Data.rar";
                    string path_file = Roaming_path + @"\phpDesigner\";
                    ExtractRAR(rar_file, path_file);
                    File.Copy(App_path + @"\DBBACKUP\phpDesigner\phpdesigner.xml", Roaming_path + @"\phpdesigner.xml", true);

                    t.Abort();
                    MessageBox.Show("Restore completed!", "Finish");
                }
                else
                {
                    t.Abort();
                    MessageBox.Show("phpDesigner 8 don't install!", "Error");
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }
        }

        private void btn_bk_corelx6_Click(object sender, EventArgs e)
        {
            if (File.Exists(App_path + @"\DBBACKUP\CorelDraw") != true)
            {
                Directory.CreateDirectory(App_path + @"\DBBACKUP\CorelDraw");
            }
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                if (Is64 == true)
                {
                    string chkfile_64 = Program_64 + @"\Corel\CorelDRAW Graphics Suite X6\Programs64\CorelDRW.exe";
                    if (File.Exists(chkfile_64))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "CorelDRW")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\CorelDraw\CorelX6.rar";
                        string path_file = Roaming_path + @"\Corel\CorelDRAW Graphics Suite X6\";
                        CompressRAR(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Backup completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Corel Draw X6 don't install!", "Error");
                    }
                }
                else
                {
                    string chkfile_32 = Program_32 + @"\Corel\CorelDRAW Graphics Suite X6\Programs\CorelDRW.exe";
                    if (File.Exists(chkfile_32))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "CorelDRW")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\CorelDraw\CorelX6.rar";
                        string path_file = Roaming_path + @"\Corel\CorelDRAW Graphics Suite X6\";
                        CompressRAR(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Backup completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Corel Draw X6 don't install!", "Error");
                    }
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }

        }

        private void btn_res_corelx6_Click(object sender, EventArgs e)
        {
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                if (Is64 == true)
                {
                    string chkfile_64 = Program_64 + @"\Corel\CorelDRAW Graphics Suite X6\Programs64\CorelDRW.exe"; ;
                    if (File.Exists(chkfile_64))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "CorelDRW")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\CorelDraw\CorelX6.rar";
                        string path_file = Roaming_path + @"\Corel\CorelDRAW Graphics Suite X6\";
                        ExtractRAR(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Restore completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Corel Draw X6 don't install!", "Error");
                    }
                }
                else
                {
                    string chkfile_32 = Program_32 + @"\Corel\CorelDRAW Graphics Suite X6\Programs\CorelDRW.exe";
                    if (File.Exists(chkfile_32))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "CorelDRW")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\CorelDraw\CorelX6.rar";
                        string path_file = Roaming_path + @"\Corel\CorelDRAW Graphics Suite X6\";
                        ExtractRAR(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Restore completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Corel Draw X6 don't install!", "Error");
                    }
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }
        }

        private void btn_bk_snippet_Click(object sender, EventArgs e)
        {
            ClearSnippets();
            if (File.Exists(App_path + @"\DBBACKUP\Snippets") != true)
            {
                Directory.CreateDirectory(App_path + @"\DBBACKUP\Snippets");
            }
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                string chkfile = Program_32 + @"\Snippets\Snippets.exe";
                if (File.Exists(chkfile))
                {
                    foreach (Process app in Process.GetProcesses())
                        if (app.ProcessName == "Snippets")
                            app.Kill();
                    string rar_file = App_path + @"\DBBACKUP\Snippets\Snippets_Data.rar";
                    string path_file = Local_path + @"\Snippets\";
                    CompressRAR(rar_file, path_file);

                    t.Abort();
                    MessageBox.Show("Backup completed!", "Finish");
                }
                else
                {
                    t.Abort();
                    MessageBox.Show("Snippets don't install!", "Error");
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }
        }

        private void btn_res_snippet_Click(object sender, EventArgs e)
        {
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                string chkfile = Program_32 + @"\Snippets\Snippets.exe";
                if (File.Exists(chkfile))
                {
                    foreach (Process app in Process.GetProcesses())
                        if (app.ProcessName == "Snippets")
                            app.Kill();
                    string rar_file = App_path + @"\DBBACKUP\Snippets\Snippets_Data.rar";
                    string path_file = Local_path + @"\Snippets\";
                    ExtractRAR(rar_file, path_file);

                    t.Abort();
                    MessageBox.Show("Restore completed!", "Finish");
                }
                else
                {
                    t.Abort();
                    MessageBox.Show("Snippets don't install!", "Error");
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }
        }
        #endregion

        private void btn_bk_evernote_Click(object sender, EventArgs e)
        {
            ClearEvernote();
            if (File.Exists(App_path + @"\DBBACKUP\Evernote") != true)
            {
                Directory.CreateDirectory(App_path + @"\DBBACKUP\Evernote");
            }
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                string chkfile = Program_32 + @"\Evernote\Evernote\Evernote.exe";
                if (File.Exists(chkfile))
                {
                    foreach (Process app in Process.GetProcesses())
                        if (app.ProcessName == "Evernote")
                            app.Kill();
                    string rar_file = App_path + @"\DBBACKUP\Evernote\Evernote_Data.rar";
                    string path_file = Local_path + @"\Evernote\Evernote\";
                    CompressRAR(rar_file, path_file);

                    t.Abort();
                    MessageBox.Show("Backup completed!", "Finish");
                }
                else
                {
                    t.Abort();
                    MessageBox.Show("Evernote don't install!", "Error");
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }
        }

        private void btn_res_evernote_Click(object sender, EventArgs e)
        {
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                string chkfile = Program_32 + @"\Evernote\Evernote\Evernote.exe";
                if (File.Exists(chkfile))
                {
                    foreach (Process app in Process.GetProcesses())
                        if (app.ProcessName == "Evernote")
                            app.Kill();
                    string rar_file = App_path + @"\DBBACKUP\Evernote\Evernote_Data.rar";
                    string path_file = Local_path + @"\Evernote\Evernote\";
                    ExtractRAR(rar_file, path_file);

                    t.Abort();
                    MessageBox.Show("Restore completed!", "Finish");
                }
                else
                {
                    t.Abort();
                    MessageBox.Show("Evernote don't install!", "Error");
                }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }
        }

        private void btn_bk_corelx3_Click(object sender, EventArgs e)
        {
            if (File.Exists(App_path + @"\DBBACKUP\CorelDraw") != true)
            {
                Directory.CreateDirectory(App_path + @"\DBBACKUP\CorelDraw");
            }
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();
				
                    string chkfile_32 = Program_32 + @"\Corel\CorelDRAW Graphics Suite 13\Programs\CorelDRW.exe";
                    if (File.Exists(chkfile_32))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "CorelDRW")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\CorelDraw\CorelX3.rar";
                        string path_file = Roaming_path + @"\Corel\Graphics13\";
                        CompressRAR(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Backup completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Corel Draw X3 don't install!", "Error");
                    }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }

        }

        private void btn_res_corelx3_Click(object sender, EventArgs e)
        {
            try
            {
                Thread t = new Thread(new ThreadStart(frmMain.waitscreen));
                t.Start();

                    string chkfile_32 = Program_32 + @"\Corel\CorelDRAW Graphics Suite 13\Programs\CorelDRW.exe";
                    if (File.Exists(chkfile_32))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "CorelDRW")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\CorelDraw\CorelX3.rar";
                        string path_file = Roaming_path + @"\Corel\Graphics13\";
                        ExtractRAR(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Restore completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Corel Draw X3 don't install!", "Error");
                    }
            }
            catch
            {
                MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
            }
        }
    }
}
